<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>phasorbnk</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="phasor.html" title="phasor" />
    <link rel="next" href="phs.html" title="phs" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">phasorbnk</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="phasor.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="phs.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="phasorbnk"></a>
      <div class="titlepage"></div>
      <a id="IndexPhasorbnk" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">phasorbnk</span>
        </h2>
        <p>phasorbnk — 
      Produce an arbitrary number of normalized moving phase values.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134053952"></a>
        <h2>Description</h2>
        <p>
      Produce an arbitrary number of normalized moving phase values, accessable by an index.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134057824"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>phasorbnk</strong></span> xcps, kndx, icnt [, iphs]</pre>
        <pre class="synopsis">kres <span class="command"><strong>phasorbnk</strong></span> kcps, kndx, icnt [, iphs]</pre>
      </div>
      <div class="refsect1">
        <a id="idp134061424"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>icnt</em></span> -- maximum number of phasors to be used.
    </p>
        <p>
      <span class="emphasis"><em>iphs</em></span> -- initial phase, expressed as a fraction of a cycle (0 to 1). If -1 initialization is skipped. If <span class="emphasis"><em>iphas</em></span>&gt;1 each phasor will be initialized with a random value.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134130880"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kndx</em></span> -- index value to access individual phasors
    </p>
        <p>
      For each independent phasor, an internal phase is successively accumulated in accordance with the <span class="emphasis"><em>kcps</em></span> or <span class="emphasis"><em>xcps</em></span> frequency to produce a moving phase value, normalized to lie in the range 0 &lt;= phs &lt; 1. Each individual phasor is accessed by index <span class="emphasis"><em>kndx</em></span>.
    </p>
        <p>
      This phasor bank can be used inside a k-rate loop to generate multiple independent voices, or together with the <a class="link" href="adsynt.html" title="adsynt"><em class="citetitle">adsynt</em></a> opcode to change parameters in the tables used by <span class="emphasis"><em>adsynt</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134136464"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the phasorbnk opcode. It uses the file <a class="ulink" href="examples/phasorbnk.csd" target="_top"><em class="citetitle">phasorbnk.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp134138320"></a>
          <p class="title">
            <strong>Example 623. Example of the phasorbnk opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o phasorbnk.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Generate a sinewave table.</span>
giwave <span class="ohdr">ftgen</span> 1, 0, 1024, 10, 1 

<span class="comment">; Instrument #1</span>
<span class="oblock">instr</span> 1
  <span class="comment">; Generate 10 voices.</span>
  icnt <span class="op">=</span> 10 
  <span class="comment">; Empty the output buffer.</span>
  asum <span class="op">=</span> 0 
  <span class="comment">; Reset the loop index.</span>
  kindex <span class="op">=</span> 0 

<span class="comment">; This loop is executed every k-cycle.</span>
<span class="olabel">loop</span><span class="op">:</span> 
  <span class="comment">; Generate non-harmonic partials.</span>
  kcps <span class="op">=</span> (kindex<span class="op">+</span>1)<span class="op">*</span>100<span class="op">+</span>30 
  <span class="comment">; Get the phase for each voice.</span>
  aphas <span class="opc">phasorbnk</span> kcps, kindex, icnt 
  <span class="comment">; Read the wave from the table.</span>
  asig <span class="opc">table</span> aphas, giwave, 1 
  <span class="comment">; Accumulate the audio output.</span>
  asum <span class="op">=</span> asum <span class="op">+</span> asig 

  <span class="comment">; Increment the index.</span>
  kindex <span class="op">=</span> kindex <span class="op">+</span> 1

  <span class="comment">; Perform the loop until the index (kindex) reaches </span>
  <span class="comment">; the counter value (icnt).</span>
  <span class="octrl">if</span> (kindex <span class="op">&lt;</span> icnt) <span class="octrl">kgoto</span> <span class="olabel">loop</span> 

  <span class="opc">out</span> asum<span class="op">*</span>3000
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Play Instrument #1 for two seconds.</span>
<span class="stamnt">i</span> 1 0 2
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Generate multiple voices with independent partials. This example is better with <span class="emphasis"><em>adsynt</em></span>. See also the example under <a class="link" href="adsynt.html" title="adsynt"><em class="citetitle">adsynt</em></a>, for k-rate use of <span class="emphasis"><em>phasorbnk</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134144480"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Peter Neubäcker</td>
          </tr>
          <tr>
            <td>Munich, Germany</td>
          </tr>
          <tr>
            <td>August 1999</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound version 3.58</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="phasor.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="phs.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">phasor </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> phs</td>
        </tr>
      </table>
    </div>
  </body>
</html>
